package com.famdoc.Service.Impl;

import com.famdoc.Mapper.CrowdMapper;
import com.famdoc.Pojo.dto.Result;
import com.famdoc.Pojo.entity.Crowd;
import com.famdoc.Pojo.vo.CrowdVo;
import com.famdoc.Service.CrowdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class CrowdServiceImpl implements CrowdService {

    @Autowired
    private CrowdMapper crowdMapper;

    /**
     * 获取所有群分类
     * @return
     */
    @Override
    public Result getAllCrowd() {
        List<Crowd> crowdList =crowdMapper.getAllCrowd();
        return Result.success(crowdList);
    }

    /**
     * 获取人群分类
     * @param crowds
     * @return
     */
    @Override
    public Result getCrowd(String crowds) {
        System.out.println(crowds);
        List<String> crowdNames = Arrays.asList(crowds.split(","));
        System.out.println(crowdNames);
        List<Crowd> crowdList = crowdMapper.getCrowd(crowdNames);
        List<String> symptomList = new ArrayList<>();
        for (Crowd crowd : crowdList) {
            List<String> symptom = Arrays.asList(crowd.getSymptom().split(","));
            symptomList.addAll(symptom);
        }
        CrowdVo crowdVo = new CrowdVo(crowdNames,symptomList);
        return Result.success(crowdVo);
    }

}
